<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

<script type="text/javascript" src="<c:url value="/layout/javascript/largePaginator.js"/>">/**/</script>
<script type="text/javascript" src="<c:url value="/layout/javascript/jquery.jtruncate.js"/>">/**/</script> 
<script type="text/javascript" src="<c:url value="/layout/javascript/jquery.form.js"/>">/**/</script>
<script type="text/javascript" src="<c:url value="/layout/javascript/form.js"/>">/**/</script>
<script type="text/javascript">
var subCatErrOpts = {
   msg : "<bean:message key="subcat.load.msg" bundle="errors"/>",
   boxTitle : "<bean:message key="subcat.load.boxTitle" bundle="errors"/>",
   msgStatus: "<bean:message key="subcat.load.msgStatus" bundle="errors"/>"
};

$(document).ready(function(){
    var options = { 
        //target:        '#hiddenresult', 
        beforeSubmit:  function () {
                           $('#Searchresult').empty();
                           $('#Searchresult').html('<img alt="<bean:message key="wait.message"/>" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="wait.message"/>');
                       }, 
        success:       function (data) {
				            var identity = data.slice(0,68);
				            // Riceve come risposta il box di errore di validazione
				            if (identity.search('#boxvalidation') != -1) {
				                $('#validationbox').html(data);
				                $('#Searchresult').empty();
				            } else { // Riceve la lista di ticket
				               $('#hiddenresult').html(data);
				               paginateFaqHistory();
				            }
				       },
        error:         function () {
                    	   showErrorDialog('#dialog', 
                            	   { msg: "<bean:message key="faq.history.form.msg" bundle="errors"/>",
                    		         boxTitle: "<bean:message key="faq.history.form.boxTitle" bundle="errors"/>",
                    		         msgStatus: "<bean:message key="faq.history.form.msgStatus" bundle="errors"/>" });
                       }  
    };

    $('#form_FaqsHistory').ajaxForm(options);

    $("#categories").change(function () {
		selectSubCategoriesForFaqs($(this), '${pageContext.request.contextPath}/ticket/loadsubcategories.do');
	});

	selectSubCategoriesForFaqs($('#categories'), '${pageContext.request.contextPath}/ticket/loadsubcategories.do', function () {
		$('#form_FaqsHistory').submit();
	});
});
</script>

<div id="content">
		<!--FORM-->
		<fieldset id="fieldset">
			<legend class="fieldsetLabel"><bean:message key="faq" bundle="faq"/></legend>
			<div id="form_containerFaqs">
				<html:form styleId="form_FaqsHistory" styleClass="appnitro" action="/ticket/getfaqlist.do">
				<html:hidden property="userID" styleId="userID"/>
				<div id="divFaqs">	
					<ul id="ulFaqs">
					<li id="li_2Faqs" >
						<label class="description" for="contents"><bean:message key="faq.content" bundle="faq"/></label>
						<div>
							<html:text styleId="contents" property="contents" styleClass="element text large" maxlength="255" /> 
						</div> 
					</li>			
					<li id="li_5Faqs" >
						<label class="description" for="category"><bean:message key="faq.category" bundle="faq"/></label>
						<div>
                            <html:select property="catID" styleClass="element select large" styleId="categories">
                                <option  selected="selected" value=""><bean:message key="select.option.all"/></option>
                                <html:options collection="category" property="categoryID" labelProperty="name" />
                            </html:select>						    
						</div> 
					</li>
					<li id="li_6Faqs" >
						<label class="description" for="subCategories"><bean:message key="faq.subcategory" bundle="faq"/></label>
						<div>
							<select name="subCategories" class="element select large" id="subCategories">
							</select>
						</div> 
					</li>				
					<li id="buttonsFaqs">
						<html:submit styleId="searchButton" styleClass="button_text">
						  <bean:message key="button.search"/>
						</html:submit>
					</li>
					</ul>
				</div>	
				</html:form>	
				
				<div id="ListFaqs">
					<div id="Pagination" class="pagination"> </div>
					<br style="clear:both;" />
					<ul id="label">
	        			<li class="fd"><bean:message key="faq.date" bundle="faq"/></li>
	        			<li class="fCat"><bean:message key="faq.category" bundle="faq"/></li>
	        			<li class="ft"><bean:message key="faq.title" bundle="faq"/></li>
	        			<li class="fCont"><bean:message key="faq.content" bundle="faq"/></li>
			        </ul>
					<div id="Searchresult">
						<img alt="<bean:message key="wait.message"/>" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="wait.message"/>
					</div>
			        
			        <!-- Container element for all the Elements that are to be paginated -->
			        <div id="hiddenresult" style="display:none;">
			        </div>
				</div>
			</div>
		</fieldset>
</div>	